console.log("loading instance.js");

Vectrite.Instance = Vectrite.Class();
Vectrite.Instance.prototype = {
   vrites: {},
   styles: {},
   tick: 0,
   initialize: function(context) {
      Vectrite.inst = this;
      this.context = context;
      this.self = this;
   },
   background: function(context) {
      context.beginPath();
      context.fillStyle = "rgb(0,128," + this.tick + ")";
      context.rect(0,0, $('#canvas1')[0].width, $('#canvas1')[0].height);
      context.fill();
   },
   draw: function() {
      this.background(this.context);
      for (vrite in this.vrites) {
         this.vrites[vrite].draw();
      }
      this.tick++;
      this.tick %= 255;
   },
   drawEnabled: 0,
   drawInterval: 0,
   toggleDraw: function() {
      this.drawEnabled = !this.drawEnabled;
      if (this.drawEnabled && !this.drawInterval) {
         this.drawInterval = setInterval(Vectrite.bind(this, this.draw), 50);
      }
      else if (this.drawInterval) {
         clearInterval(this.drawInterval);
         this.drawInterval = 0;
      }
   },
   /* addStyle({n: 'style identifier', func: function (context) { }) */
   addStyle: function(style) { this.styles[style.n] = style.func },
   /* addVrite({n: 'vrite identifier', a: 'hash of animations'}, startinganimation) */
   addVrite: function(vrite, state, x, y) { this.vrites[vrite.n] = new Vectrite.Vrite(vrite.a, vrite.t, state, x, y); }
}
console.log("loaded instance.js");